190. 颠倒二进制位
为保证权益,题目请参考 190. 颠倒二进制位(From LeetCode).
解决方案1
CPP
C++
#include <iostream>
using namespace std;
class Solution {
public:
static uint32_t reverseBits(uint32_t n) {
uint32_t t = 1;
uint32_t ans = 0;
uint32_t at = 0 | t << 31;
for (int i = 0; i < 32; i++) {
if (t & n) {
ans = ans | at;
}
t = t << 1;
at = at >> 1;
}
return ans;
}
};
int main() {
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24